﻿
Public Class nuevo_usuario

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim qry As String
        If ValidarVacio(Me, Me.ErrorProvider1) = True Then
            qry = "insert into usuarios (usr_rut, nombre, apellido, grup_id, clave) values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & ComboBox1.SelectedIndex + 1 & "','" & encriptar(TextBox4.Text) & "')"
            'MsgBox(qry)
            Me.Close()
            Try
                EjecutaConsulta(qry)
            Catch ex As SqlClient.SqlException
                MsgBox("Error: " & ex.Message)
            End Try
        End If

    End Sub

    Private Sub nuevo_usuario_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        CargarCombobox("select * from grupo", ComboBox1, "grup_id", "grup_descripcion")
    End Sub

    Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        If ValidarRut(TextBox1.Text, TextBox1, ErrorProvider1) = False Then

            TextBox1.Focus()
        End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        'MsgBox("valor= " & ComboBox1.Display & "indice=" & ComboBox1.SelectedValue)
    End Sub
End Class